# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models


# Create your models here.


class Devices(models.Model):
    name = models.CharField(verbose_name='设备名称', max_length=30)
    code = models.CharField(verbose_name='设备编号', max_length=50, null=True, blank=True)
    qr_code = models.CharField(verbose_name='二维码信息', max_length=100, null=True, blank=True)
    brand = models.CharField(verbose_name='品牌', max_length=50, null=True, blank=True)
    model = models.CharField(verbose_name='型号', max_length=50, null=True, blank=True)
    number = models.CharField(verbose_name='产品编号', max_length=50, null=True, blank=True)
    supplier = models.CharField(verbose_name='供应商', max_length=50, null=True, blank=True)
    supplier_phone = models.CharField(verbose_name='供应商电话', max_length=50, null=True, blank=True)
    ip = models.CharField(verbose_name='ip地址', max_length=20, null=True, blank=True)
    address = models.CharField(verbose_name='位置地点', max_length=100, null=True, blank=True)
    address_latitude = models.CharField(verbose_name='位置纬度', max_length=30, null=True, blank=True)
    address_longitude = models.CharField(verbose_name='位置经度', max_length=30, null=True, blank=True)
    pile_no = models.CharField(verbose_name='桩号', max_length=20, null=True, blank=True)
    construction_units = models.CharField(verbose_name='施工单位', max_length=50, null=True, blank=True)
    construction_units_contact = models.CharField(verbose_name='施工单位联系人', max_length=50, null=True, blank=True)
    construction_units_phone = models.CharField(verbose_name='施工单位联系电话', max_length=20, null=True, blank=True)
    use_units_contact = models.CharField(verbose_name='使用单位联系人', max_length=50, null=True, blank=True)
    use_units_phone = models.CharField(verbose_name='使用单位联系电话', max_length=20, null=True, blank=True)
    maintenance_units = models.CharField(verbose_name='维保单位', max_length=50, null=True, blank=True)
    maintenance_units_contact = models.CharField(verbose_name='维保单位联系人', max_length=50, null=True, blank=True)
    maintenance_units_phone = models.CharField(verbose_name='维保单位电话', max_length=20, null=True, blank=True)
    status = models.BooleanField(verbose_name='状态', default=True)
    create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_date = models.DateTimeField(verbose_name='修改时间', auto_now=True)

    class Meta:
        db_table = 't_devices'
        verbose_name = "设备信息"
        verbose_name_plural = "设备信息"
        permissions = (
            ("add_device", u"新增设备信息"),
            ("change_device", u"修改设备信息"),
            ("delete_device", u"删除设备信息"),
        )

    def __str__(self):
        return self.name


class DeviceImg(models.Model):
    device = models.ForeignKey(Devices, blank=True, null=True, verbose_name='对应设备')
    name = models.CharField(verbose_name='文件名', max_length=30)
    desc = models.CharField(verbose_name='文件备注', max_length=100, null=True, blank=True)
    url = models.CharField(verbose_name='url地址', max_length=500, null=True, blank=True)
    path = models.CharField(verbose_name='文件路径', max_length=500, null=True, blank=True)
    # type = models.IntegerField(verbose_name='文件类别', choices=FILE_TYPE, default=0)
    status = models.BooleanField(verbose_name='状态', default=True)
    create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_date = models.DateTimeField(verbose_name='修改时间', auto_now=True)

    class Meta:
        db_table = 't_devices_image'
        verbose_name = "设备图片"
        verbose_name_plural = "设备图片"

    def __str__(self):
        return self.name
